package com.example.himalayaproject.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.example.himalayaproject.R;

import java.util.List;


/**
 * Created by Administrator on 2016/12/5.
 */
public class SettingRecyclerAdapter extends RecyclerView.Adapter<SettingRecyclerAdapter.ViewHolder> implements View.OnClickListener {
    private Context context;
    private List<String> titleList;
    private OnChildClickListener listener;
    private RecyclerView recyclerView;

    public SettingRecyclerAdapter(Context context, List<String> titleList) {
        this.context = context;
        this.titleList = titleList;
    }

    @Override
    public int getItemCount() {
        Log.d("1620",titleList.size()+"");
        return titleList.size();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.fragment_ower_setting_item, parent, false);
        view.setOnClickListener(this);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    public void setListener(OnChildClickListener listener) {
        this.listener = listener;
    }

    @Override
    public void onAttachedToRecyclerView(RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
        this.recyclerView = recyclerView;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {;
        holder.textView.setText(titleList.get(position));
        if (position == 1 | position == 5) {
            holder.button.setVisibility(View.VISIBLE);
//            if(position==7){
//                holder.otherTextView.setVisibility(View.VISIBLE);
//            }
//        }else if(position==15){
//            holder.linearLayout.setVisibility(View.VISIBLE);
//            holder.otherButton.setVisibility(View.VISIBLE);
        } else {
            holder.button.setVisibility(View.GONE);
            holder.otherButton.setVisibility(View.VISIBLE);
        }
    }


    @Override
    public void onClick(View v) {
        if (recyclerView != null && listener != null) {
            int position = recyclerView.getChildAdapterPosition(v);
            listener.onChildClick(position);
        }
    }

    public interface OnChildClickListener {
        void onChildClick(int position);
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        private TextView textView;
        private Button button, otherButton;

        public ViewHolder(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.owner_setting_item_tv);
            button = (Button) itemView.findViewById(R.id.owner_setting_item_but);
            otherButton = (Button) itemView.findViewById(R.id.owner_setting_item_but2);
        }
    }
}
